﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using RobotEscape.Entities;
using System.Collections.Generic;
using System.Linq;

namespace RobotEscape.Screens
{
    public abstract class ScreenBase
    {
        public bool paused = false;
        public virtual void Update(GameTime time)
        {
            foreach (EntityBase entity in this.entities)
            {
                if (!paused || !entity.pausable)
                    entity.Update(time);
            }
        }

        public virtual void Init()
        {
        }

        public virtual void Remove()
        {
            for (int i = this.entities.Count - 1; i >= 0; i--)
            {
                RemoveEntity(this.entities[i]);
            }
        }

        public List<EntityBase> entities = new List<EntityBase>();
        public void AddEntity(EntityBase entity)
        {
            if (entity.uiElement != null)
                if (!Game.Instance.Canvas.Children.Contains(entity.uiElement))
                    Game.Instance.Canvas.Children.Add(entity.uiElement);
            entities.Add(entity);
        }

        public void RemoveEntity(EntityBase entity)
        {
            if (entity.uiElement != null)
                if (Game.Instance.Canvas.Children.Contains(entity.uiElement))
                    Game.Instance.Canvas.Children.Remove(entity.uiElement);
            entities.Remove(entity);
        }
    }
}
